import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

const useRouter = () => {
  const { pathname } = useLocation();
  let token = localStorage.getItem("token");
  const nav = useNavigate();
  useEffect(() => {
    const whileFun = ["/home/index"];
    if (!whileFun.includes(pathname) && !token) {
      nav("/login");
    }
  }, [pathname]);
};
export default useRouter;
